Skip to content

Conversation

@sobomax
Copy link
Contributor

@sobomax sobomax commented Dec 1, 2025

Summary
Port add_contact_alias() and handle_ruri_alias() functions

Details
Those are slightly better version of the fix_nated_contact() originating from Kamailio.

The problem with fix_nated_contact() is that it could cause RURI for in-dialog requests contain a different IP address as compared to the Contact in the initial INVITE.

Most endpoints are fine with that, however tere are some, notably MS Teams, which would reject such request with:

SIP/2.0 500 Internal Server Error
Reason: Q.850;cause=47;text="76a7afc3-d033-4988-9000-f70b41e4db1b;RURI in request has invalid FQDN value"

The full exchange when using fix_nated_contact() is as follows:

UA->OpenSIPS (initial INVITE):

opensips[NNNN]: RECEIVED message from 10.2.80.32:5060:
INVITE sip:[...]
Contact: <sip:[...]@10.2.80.22:5060>
                    ^^^^^^^^^^

OpenSIPS->UA:

SIP/2.0 100 Giving it a try
SIP/2.0 200 OK

UA->OpenSIPS:

ACK sip:[...]

OpenSIPS->UA (re-INVITE):

opensips[NNNN]: SENDING message to 10.2.80.32:5060:
INVITE sip:[...]@10.2.80.32:5060 SIP/2.0
                 ^^^^^^^^^^

UA->OpenSIPS:

SIP/2.0 500 Internal Server Error

Solution
Use add_contact_alias() in the INVITE/200 OK paths and handle_ruri_alias() in in-dialog request path.

UA->OpenSIPS (initial INVITE):

opensips[NNNN]: RECEIVED message from 10.2.80.32:5060:
INVITE sip:[...]
Contact: <sip:[...]@10.2.80.22:5060>
                    ^^^^^^^^^^

OpenSIPS->UA:

SIP/2.0 100 Giving it a try

OpenSIPS->B2BUA (initial INVITE):

opensips[NNNN]: SENDING message to [...]:
INVITE sip:[...]
Contact: <sip:[...]@10.2.80.22:5060;alias=10.2.80.32~5060~1>
                    ^^^^^^^^^^

B2BUA->OpenSIPS (re-INVITE):

opensips[NNNN]: RECEIVED message from [...]:
INVITE sip:[...]@10.2.80.22:5060;alias=10.2.80.32~5060~1 SIP/2.0
                 ^^^^^^^^^^

OpenSIPS->UA (re-INVITE):

opensips[NNNN]: SENDING message to 10.2.80.32:5060:
                                   ^^^^^^^^^^
INVITE sip:[...]@10.2.80.22:5060 SIP/2.0
                 ^^^^^^^^^^

Compatibility
Should not be any if used correctly. Special test case for the voiptests has been created and will be enabled once the change is merged into the opensips/master.

@sobomax sobomax requested a review from liviuchircu December 1, 2025 20:54
@github-actions
Copy link

github-actions bot commented Jan 1, 2026

Any updates here? No progress has been made in the last 30 days, marking as stale.

@github-actions github-actions bot added the stale label Jan 1, 2026
Those are slightly better version of the fix_nated_contact()
originating from Kamailio.

The problem with fix_nated_contact() is that it could cause
RURI for in-dialog requests contain a different IP address as
compared to the Contact in the initial INVITE.

Most endpoints are fine with that, however tere are some,
notably MS Teams, which would reject such request with:

SIP/2.0 500 Internal Server Error
Reason: Q.850;cause=47;text="76a7afc3-d033-4988-9000-f70b41e4db1b;RURI in request has invalid FQDN value"

The full exchange when using fix_nated_contact() is as follows:

UA->OpenSIPS (initial INVITE):

opensips[42757]: RECEIVED message from 10.2.80.32:5060:
INVITE sip:[...]
Contact: <sip:[...]@10.2.80.22:5060>
                    ^^^^^^^^^^

OpenSIPS->UA:

SIP/2.0 100 Giving it a try

SIP/2.0 200 OK

UA->OpenSIPS:

ACK sip:[...]

OpenSIPS->UA (re-INVITE):

opensips[42759]: SENDING message to 10.2.80.32:5060:
INVITE sip:[...]@10.2.80.32:5060 SIP/2.0
                 ^^^^^^^^^^

UA->OpenSIPS:

SIP/2.0 500 Internal Server Error
@stale stale bot removed the stale label Jan 2, 2026
@sobomax sobomax requested a review from razvancrainea January 2, 2026 17:30
@bogdan-iancu
Copy link
Member

Hi @sobomax , thanks for the contribution here. Here are some first thoughts:

  • yes, indeed, the problem addressed by this PR is real
  • there are already ways to address the problem described here:
    ** use the topo hiding with dialog module - it is doing more or less the same as you manually do , but is a simpler and more elegant way
    ** you can achieve 100% the same results with scripting, by adding the extra Contact param via fix_nated_contact() (see uri_params func param, where you can store as base64 encoded the full original URI); on sequential requests, it's a simple transformation to fetch (from URI param) and replace the RURI.
    ** even simpler, if using the dialog module (without TH), you can store the received Contact URI into a dlg val and restore it later, it something trivial.
  • storing data into the SIP req is not always the best approach; beside leaking network information, you rely on the end points to correctly do their jobs (like mirroring that param) - history taught us (see the RR/Route mess) that reality is a bit different.

The benefit of these new functions is (as far as I can understand) to simplify a bit the scripting IF you do NOT WANT to use dialog support. Otherwise, it may complicate even more the scripting, as the user has to use more functions. Maybe we can add a new flag to fix_nated_contact(), in order to add this new param ? And we can use the "maddr" param (standard) which is automatically recognized by OpenSIPS (in routing RURI) for overriding the actual RURI domain/port

@bogdan-iancu bogdan-iancu self-assigned this Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants